home *** CD-ROM | disk | FTP | other *** search
/ The Trig Explorer / The Trig Explorer.iso / mac / Explorer / ANGLES.dxr / 00113.ls < prev    next >
Encoding:
Text File  |  1998-07-22  |  1.4 KB  |  37 lines

  1. on mouseDown
  2.   set xCenter to ((the left of sprite 4 + the right of sprite 4) / 2) + 2
  3.   set yCenter to ((the top of sprite 4 + the bottom of sprite 4) / 2) + 2
  4.   set radius to the width of sprite 4 / 2
  5.   puppetSprite(the clickOn, 1)
  6.   puppetSprite(5, 1)
  7.   repeat while the stillDown
  8.     set mx to the mouseH
  9.     set my to the mouseV
  10.     set xAtMouse to mx - xCenter
  11.     set yAtMouse to my - yCenter
  12.     if xAtMouse <> 0 then
  13.       set angleAtMouse to atan(float(abs(yAtMouse)) / float(abs(xAtMouse)))
  14.       if angleAtMouse = 0 then
  15.         set yAtCircle to 0
  16.         set xAtCircle to radius * (xAtMouse / abs(xAtMouse))
  17.       else
  18.         set yAtCircle to sin(angleAtMouse) * float(radius) * (yAtMouse / abs(yAtMouse))
  19.         set xAtCircle to cos(angleAtMouse) * float(radius) * (xAtMouse / abs(xAtMouse))
  20.       end if
  21.     else
  22.       set xAtCircle to 0
  23.       if yAtMouse <> 0 then
  24.         set yAtCircle to radius * (yAtMouse / abs(yAtMouse))
  25.       else
  26.         set yAtCircle to radius
  27.       end if
  28.     end if
  29.     set the locH of sprite the clickOn to xCenter + xAtCircle
  30.     set the locV of sprite the clickOn to yCenter + yAtCircle
  31.     drawLine(6, yCenter, xCenter, the locV of sprite the clickOn, the locH of sprite the clickOn)
  32.     set the locH of sprite 5 to ((the left of sprite 6 + the right of sprite 6) / 2) + 10
  33.     set the locV of sprite 5 to ((the top of sprite 6 + the bottom of sprite 6) / 2) - 20
  34.     updateStage()
  35.   end repeat
  36. end
  37.